import pygame
import sys

pygame.init()

size=width,height = 700,700
bg=(255,255,255)
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
pygame.display.set_caption('乌龟')

turtle = pygame.image.load('乌龟.jpg')
turtle_right = pygame.transform.rotate(turtle,90)
turtle_top = pygame.transform.rotate(turtle,180)
turtle_left = pygame.transform.rotate(turtle, 270)
turtle_bottom = turtle
turtle = turtle_top
speed = [-5, 0]

turtle_position=turtle.get_rect()

l_head =  pygame.transform.flip(turtle,True,False)
r_head = turtle

fullscreen =False
list1=[]


while True :
    
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
            
        if event.type == pygame.VIDEORESIZE:
            size = event.size
            width,height = size
            if not fullscreen :
                screen = pygame.display.set_mode(size,pygame.RESIZABLE)

    turtle_position = turtle_position.move(speed)
    
    if turtle_position.bottom>height:
        turtle=turtle_bottom
        turtle_position=turtle_rect=turtle.get_rect()
        turtle_position.bottom=height
        speed = [5, 0]
        
        
    if turtle_position.right > width:
        turtle=turtle_right
        turtle_position=turtle_rect=turtle.get_rect()
        turtle_position.left=width-turtle_rect.width
        turtle_position.top=height-turtle_rect.height
        speed = [0, -5]
        
    if turtle_position.top < 0:
        turtle=turtle_top
        turtle_position=turtle_rect=turtle.get_rect()
        turtle_position.left=width-turtle_rect.width
        speed = [-5, 0]
        
    if turtle_position.left<0:
        turtle=turtle_left
        turtle_position=turtle_rect=turtle.get_rect()
        turtle_position.left=0
        speed = [0,5]
                    
    screen.fill(bg)
    screen.blit(turtle,turtle_position)
    pygame.display.flip()
    pygame.time.delay(10)

    
